package com.mp3s.interface3;

import java.text.DecimalFormat;

import cn.hutool.core.convert.Convert;

public class QuoteDataC{

    public float toFloat(String str){
       return Float.parseFloat(str);
    }

    public static float open(QuoteData now, QuoteData last){
        float f =  (float)((Float.parseFloat(now.getOpen()) - Float.parseFloat(last.getOpen()))*100/Float.parseFloat(last.getOpen()));
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        String formatted = decimalFormat.format(f);
        return Convert.toFloat(formatted);
    }

    public static float volume(QuoteData now, QuoteData last){
        return (float)(Float.parseFloat(now.getVolume()) - Float.parseFloat(last.getVolume()))*100/Float.parseFloat(last.getVolume());
    }
    
    public static float close(QuoteData now, QuoteData last){
        float f = (float)((Float.parseFloat(now.getClose()) - Float.parseFloat(last.getClose()))*100/Float.parseFloat(last.getClose()));
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        String formatted = decimalFormat.format(f);
        return Convert.toFloat(formatted);
    }

    public static float high(QuoteData now, QuoteData last){
        float f =  (float)((Float.parseFloat(now.getHigh()) - Float.parseFloat(last.getHigh()))*100/Float.parseFloat(last.getHigh()));
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        String formatted = decimalFormat.format(f);
        return Convert.toFloat(formatted);
    }

    public static float low(QuoteData now, QuoteData last){
        float f =  (float)((Float.parseFloat(now.getLow()) - Float.parseFloat(last.getLow()))*100/Float.parseFloat(last.getLow()));
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        String formatted = decimalFormat.format(f);
        return Convert.toFloat(formatted);
    }

} 

